ADO.NET

How to overwite the properties in partial class using asp.net?

How to overwite the properties in partial class using asp.net?, someone asked me to explain?

We can use metadata to add functionality to entities by adding properties in a metadata class with attributes that we can affect the behavior of entities implemented with partial class called metadata classes.

When you needed to update the entities model but you do not want to lose the annotations when the entity class is regenerated. Metadata class allows adding functionality such as validation and child entity child entity compositon.

Entity generated for post Table:

  public partial class Post
    {       
       public int PostId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }

    }

To add metadata class manually:

[Table("Post")]
    [MetadataType(typeof(PostMetadata))]
    public partial class Post
    {
        internal sealed class PostMetadata
        {
            [AllowHtml]
            public string Title { get; set; }
     [AllowHtml]
            [StringLength(500, ErrorMessage = "Description can acceptmaximum 500 characters.")]
           public string Description { get; set; }
            [AllowHtml]
            [Required]

        }
    }

Post your comments / questions